package net.borlis.rest;

import net.borlis.processor.api.object.UserObject;
import net.borlis.processor.api.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.math.BigInteger;

import static org.springframework.web.bind.annotation.RequestMethod.*;

/**
 * Created by borlis on 24.12.2014.
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private HttpServletRequest context;

    @RequestMapping(value = "/create", method = PUT)
    public UserObject create(
            @RequestParam(value = "name") String name,
            @RequestParam(value = "surname") String surname,
            @RequestParam(value = "company") String company) {
        return userService.create(name, surname, company);
    }

    @RequestMapping(value = "/read", method = GET)
    public UserObject read(
            @RequestParam(value = "id") BigInteger id) {
        return userService.read(id);
    }

    @RequestMapping(value = "/update", method = POST)
    public UserObject update(
            @RequestParam(value = "id") BigInteger id,
            @RequestParam(value = "name") String name,
            @RequestParam(value = "surname") String surname,
            @RequestParam(value = "company") String company) {
        return userService.update(id, name, surname, company);
    }

    @RequestMapping(value = "/delete", method = DELETE)
    public void delete(
            @RequestParam(value = "id") BigInteger id) {
        userService.delete(id);
    }
}
